package org.laowenchao.dao;

import java.util.List;

import javax.jdo.PersistenceManager;

import org.laowenchao.pojo.Article;
import org.laowenchao.server.PMF;

public class ArticleDao{

	
	public void save(Article article)
	{
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try {
			pm.makePersistent(article);
		} finally {
			pm.close();
		}
	}
	
	public List<Article> getArticles()
	{
        PersistenceManager pm = PMF.get().getPersistenceManager();
        String query = "select from " + Article.class.getName();
        try{
        List articles = (List) pm.newQuery(query).execute();
        return articles;
        }finally
		{
			pm.close();
		}
	}
	
	public Article getArticleById(Long id)
	{

		PersistenceManager pm = PMF.get().getPersistenceManager();
		try
		{
			return (Article) pm.getObjectById(Article.class,id);
		}finally
		{
			pm.close();
		}
	}
	
	
	public static void main(String[] args)
	{
		ArticleDao ad= new ArticleDao();
		ad.getArticles();
	}
}
